#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import subprocess
newCronLine = "* * * * * /usr/bin/python /usr/local/zy-pkgs/skripty/zyxel_main.py > /usr/local/zy-pkgs/skripty/backup.log 2>&1 \n\n\n"

try:
    with open("/var/spool/cron/crontabs/root", "a") as f: # NSA310
        f.write(newCronLine)
except IOError:
    with open("/usr/local/spool/cron/crontabs/root", "a") as f: # to je mozna pro NSA325
        f.write(newCronLine)
        

subprocessString = ("/etc/init.d/crond.sh restart")
myCatch = subprocess.Popen(subprocessString, stdout = subprocess.PIPE, stderr=subprocess.PIPE, shell = True)
output, err = myCatch.communicate()
exitCode = myCatch.wait()
if exitCode:
    print "nespustilo se"
